#!/bin/bash

# 参数解析
CLEAN_NPZ=true  # 默认不清理npz文件

# 默认提交信息
DEFAULT_MSG="自动构建提交 $(date +'%Y-%m-%d %H:%M:%S')"

# 检查是否提供了提交信息
if [ -z "$1" ]; then
    echo "未提供提交信息，使用默认值: $DEFAULT_MSG"
    COMMIT_MSG="$DEFAULT_MSG"
else
    COMMIT_MSG="$1"
fi

# 清理构建目录
echo "清理构建目录..."
rm -rf build install log

# 条件清理校准文件
if [ "$CLEAN_NPZ" = true ]; then
    echo "清理校准文件..."
    cd src/lane_detection/calib_params
    rm -f *.npz
    cd ../../..
fi

# Git操作
echo "提交Git变更..."
git add .
git commit -m "$COMMIT_MSG" 
git push || echo "Git推送失败（可能无变更）"

# 构建
echo "开始构建..."
export PATH=/usr/bin:$PATH
colcon build